package org.tourism.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.tourism.entity.Hotel;
import org.tourism.mapper.HotelMapper;
import org.tourism.service.HotelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wuling
 * @since 2024-07-05
 */
@Service
public class HotelServiceImpl extends ServiceImpl<HotelMapper, Hotel> implements HotelService {
    @Autowired
    private HotelMapper hotelMapper;
    QueryWrapper<Hotel> queryWrapper = new QueryWrapper<Hotel>();
    @Override
    public int insertHotel(Hotel hotel) {
        return hotelMapper.insert(hotel);
    }

    @Override
    public int updateHotel(Hotel hotel) {
        return hotelMapper.updateById(hotel);
    }

    @Override
    public int deleteHotel(Hotel hotel) {
        return hotelMapper.deleteById(hotel.getId());
    }

    @Override
    public Hotel getHotelById(int id) {
        return hotelMapper.selectById(id);
    }

    @Override
    public Hotel getHotelByName(String hotelName) {
        queryWrapper.eq("name", hotelName);
        return hotelMapper.selectOne(queryWrapper);
    }

    @Override
    public Hotel getHotelByLocation(String hotelLocation) {
        queryWrapper.eq("location", hotelLocation);
        return  hotelMapper.selectOne(queryWrapper);
    }

    @Override
    public List<Hotel> getAllHotels() {
        return hotelMapper.selectList(null);
    }
}
